Update logging source generator to support generic methods#7331
Open
Update logging source generator to support generic methods#7331
Conversation
…gingMethodHasAllowsRefStructConstraint Co-authored-by: svick <287848+svick@users.noreply.github.com>
Co-authored-by: svick <287848+svick@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update telemetry logging source generator for recent changes
Support generic methods in logging source generator (lift LOGGEN007 restriction)
Feb 23, 2026
Copilot stopped work on behalf of
svick due to an error
February 23, 2026 12:40
…aints code Co-authored-by: svick <287848+svick@users.noreply.github.com>
…StructConstraint) Co-authored-by: svick <287848+svick@users.noreply.github.com>
Copilot
AI
changed the title
Support generic methods in logging source generator (lift LOGGEN007 restriction)
Lift generic method restriction in logging source generator (LOGGEN007 → Feb 23, 2026
allows ref struct only)
svick
approved these changes
Feb 23, 2026
Member
|
cc: @evgenyfedorov2 |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Microsoft.Gen.Logging source generator to allow generic logging methods, while keeping LOGGEN007 only for the C# 13 allows ref struct anti-constraint (which can’t be represented safely in the generated state).
Changes:
- Allow generic logging methods and model/serialize method type parameters + constraints during parsing.
- Rename LOGGEN007 descriptor/message to target only
allows ref struct. - Emit generic type parameters and
whereconstraints on the generated partial method signatures; add test coverage for allowed and rejected cases.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/Generators/Microsoft.Gen.Logging/Unit/ParserTests.LogMethod.cs | Adds tests for generic logging methods, constraints, and allows ref struct rejection (skipping on older Roslyn). |
| test/Generators/Microsoft.Gen.Logging/TestClasses/GenericTestExtensions.cs | Adds representative generic logging methods for emitter/regression coverage. |
| src/Generators/Microsoft.Gen.Logging/Parsing/Resources.resx | Updates LOGGEN007 title/message to “allows ref struct” constraint wording. |
| src/Generators/Microsoft.Gen.Logging/Parsing/Resources.Designer.cs | Regenerates strongly-typed resource accessors for the renamed resource keys. |
| src/Generators/Microsoft.Gen.Logging/Parsing/Parser.cs | Removes generic-method rejection, adds type parameter capture + constraint formatting, and detects allows ref struct via reflection. |
| src/Generators/Microsoft.Gen.Logging/Parsing/DiagDescriptors.cs | Renames LOGGEN007 descriptor to LoggingMethodHasAllowsRefStructConstraint. |
| src/Generators/Microsoft.Gen.Logging/Model/LoggingMethodTypeParameter.cs | Introduces a model type for method type parameters + constraint text. |
| src/Generators/Microsoft.Gen.Logging/Model/LoggingMethod.cs | Adds TypeParameters collection to the logging method model. |
| src/Generators/Microsoft.Gen.Logging/Emission/Emitter.Utils.cs | Adds helper emission for <T...> and where T : ... clauses. |
| src/Generators/Microsoft.Gen.Logging/Emission/Emitter.Method.cs | Emits generic parameters/constraints in the generated partial method signature. |
Files not reviewed (1)
- src/Generators/Microsoft.Gen.Logging/Parsing/Resources.Designer.cs: Language not supported
Co-authored-by: svick <287848+svick@users.noreply.github.com>
…clause alignment Co-authored-by: svick <287848+svick@users.noreply.github.com>
svick
approved these changes
Feb 23, 2026
Copilot
AI
changed the title
Lift generic method restriction in logging source generator (LOGGEN007 →
Update logging source generator to support generic methods (per dotnet/runtime#124638)
Feb 23, 2026
allows ref struct only)
svick
approved these changes
Feb 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mirrors dotnet/runtime#124638. LOGGEN007 previously rejected all generic logging methods unconditionally. The restriction is narrowed to only block
allows ref structconstraints, which can't be stored as fields in the generated state struct.Changes
Arity > 0→ LOGGEN007. PopulateLoggingMethod.TypeParametersfromIMethodSymbol.TypeParameters, serializing all constraint kinds. Detectallows ref structvia reflection onITypeParameterSymbol.AllowsRefLikeType(Roslyn 4.9+; no-ops on older Roslyn).LoggingMethodIsGeneric→LoggingMethodHasAllowsRefStructConstraintwith updated message; updatedocs/list-of-diagnostics.md.LoggingMethodTypeParameter(Name,Constraints); addTypeParameterslist toLoggingMethod.<T1, T2, ...>and properly indentedwhere T : ...clauses on the generated partial method signature. UseOut(char)for single-character output.MethodGenericnow expects success; addMethodGenericWithConstraints,MethodGenericMultipleTypeParams,MethodGenericWithAllowsRefStructConstraint(skips on Roslyn < 4.9), andGenericTestExtensions.csfor emitter validation.Example
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.